<?
 require_once("../inc/email.php");
 require_once("../inc/users.php");
 
 if(isset($_POST['id']))
 {
 	
	if($_POST['CreateEmail'] == 1)
	{
		$add_result = AddEmail($_POST);
	}
	
	else
	{
		
		
		
	}
 	//Takes POST information and Adds to database
 	$email = $_POST;
	
 }
 else
 {
	if(isset($_GET['email_id']))
 	{	
 		$email_results = getEmailEntry($_GET['email_id']);
		$email = $email_results->fetch_assoc();
		$customer_id = $_GET['id'];
		
	}
	
	//Obtain User information from database
	$customer_id = $_GET['id'];
	$user_results = getUsersInfo($customer_id);
 	$user = $user_results->fetch_assoc();
 
 	$user_name = $user['first_name']." ".$user['last_name']; 
	$create = 1;
 }

 //Obtain Email Type from database
 $types = getEmailTypes();
 
?>
<!DOCTYPE html>
 <html>
    <head>
        <meta charset="utf-8" />
        <title><?=$title ?> Add Email Address for <?=htmlentities($user_name) ?></title>
         <? require('../inc/header-info.php'); ?>
    </head>
    <body>
        <div class="container" id="nav_header">
            <? include('../inc/nav.php'); ?>
        </div>
         <div class="container" id="body">
        <form class="form-inline"  id="newEmail" method="post" action="">
  				
  				<label class="control-label">Add Email Address:</label>
  				<div class="input-append">
  					<input type="hidden" name="CreateEmail" value="<?=$create ?>">
  			    	<input type="hidden" name="id" value="<?=$customer_id ?>">
  			    	
    				<input type="email" name="address" class="span3" value="<? if(isset($email['address'])){ echo htmlentities($email['address']); } ?>" placeholder="New Email">
    				<select name="contact_type" id="contact_type" class="span2 <?=isset($results['Keyword_id']) ? 'error' : '' ?>">
    					<? while($types_row = $types->fetch_assoc()): ?>
    						<option value="<?=$types_row['id']?>"
    							<? if($types_row['id'] == $email['Contact_type_id']){ ?>selected='selected'<? } ?>><?=htmlentities($types_row['Type'])?></option>
                    	<? endwhile; ?>
					</select>
    				<button type="submit" class="btn">Add Email</button>
  				</div>
  		</form>
		</div>
		
		<script type="application/javascript" src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
		
 		<script>
 		
 			$(function()
 			{
 				
 				$("#newEmail").validate({
 						rules: 
 						{	newEmail: { required: true }	}
					
				});
			});
			
  		</script>

    </body>
 </html>